let recommen = document.getElementById('recommen')

let btn = document.getElementById('btn')

// 商品详情页界面 4.3、国内折扣商品详情页功能界面

var num = location.href.split("=")[1] //对接收的上个页面的值进行切割
    // console.log(location.href.split("=")[0]);

fn(num)

function fn(num = 20) {
    console.log(123);
    ajax({
        url: "http://chst.vip:1234/api/getmoneyctrlproduct",
        data: { productid: num },
        success(res) {
            console.log(1111);
            console.log(res.result);
            res.result.forEach(item => {
                console.log(222);
                console.log(item);
                let div = document.createElement('div') //内容区域最外层盒子
                div.id = "shop"

                // img.href=item.productInfo1//评论的超链接
                let intro = document.createElement("div") //放置产品标题的盒子
                intro.innerHTML = item.productName
                intro.id = "intro"
                let source = document.createElement('div') //放置最下面的来源事件等信息
                source.id = "source"
                source.innerHTML = `${item.productFrom} | ${item.productTime}  ${item.productTips}`
                let box = document.createElement("div") //商铺详情+商品图片的盒子
                box.id = "shop-p"
                box.innerHTML = ` ${item.productImg2}${item.productInfo} `
                let text = document.createElement("p") //商品详情文字描述
                text.innerHTML = item.productInfo1
                text.id = "text"


                let img = document.createElement("p") //商品图片大图
                img.innerHTML = item.productImgSm
                img.id = "img"
                let ul = document.createElement('div')
                ul.innerHTML = item.productCity
                let btn = document.createElement("a")
                btn.href = "moneyctrl.html" //点击跳转
                btn.innerText = "前往购买"
                btn.id = "shop-btn"


                let discuss = document.createElement("div") //评论
                discuss.innerHTML = item.productComment

                let img11 = document.getElementById("img11") //获取页面插入的图片
                console.log(img11);
                div.appendChild(intro)
                div.appendChild(source)
                div.appendChild(box)

                div.appendChild(text)

                div.appendChild(img)
                div.appendChild(ul)
                div.appendChild(btn)

                div.appendChild(img11)
                div.appendChild(discuss)
                recommen.appendChild(div)

            });
        }
    })

}


// document.querySelector('#recommen').onscroll = function () {
//     btn.onclick = function () {
//         document.querySelector('#recommen').scrollTop = 0
//     }
// }
// let btn=document.getElementById("btn")
document.querySelector('#recommen').onscroll  =   function()  {
    btn.onclick  =   function()  {

        //加入动画过度效果
        //         document.querySelector('#recommen').scrollTop = 0
        // let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        let timer = setInterval(() => {
            document.querySelector('#recommen').scrollTop -= 20
            if (document.querySelector('#recommen').scrollTop <= 0) {
                clearInterval(timer)
            }
        }, 10)


            
    }
}